package com.ethannhu.superui.view

import android.content.Context
import android.util.AttributeSet
import android.widget.LinearLayout

/**
 * 矩形 LinearLayout
 */
class SquareLinearLayout @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr) {

    /**
     * 测量空间
     */
    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)
        setMeasuredDimension(measuredWidth, measuredWidth)

        //获取测量后的宽度
        val width = measuredWidth

        //创建一个测量规格
        //设置高度等于宽度

        //让父类设置尺寸
        super.onMeasure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY))
    }
}